package com.z.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.RequestParameterBuilder;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.ParameterType;
import springfox.documentation.service.RequestParameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import java.util.ArrayList;
import java.util.List;

@EnableOpenApi
@Configuration
public class SwaggerConfiguration  {

    @Bean
    public Docket docket(){

        // 添加请求参数，我们这里把token作为请求头部参数传入后端
        RequestParameterBuilder requestParameterBuilder = new RequestParameterBuilder();

        RequestParameter token = requestParameterBuilder.name("token")
                .description("请求接口时，携带token令牌")
                .in(ParameterType.HEADER)
                .required(false)
                .build();


        List<RequestParameter> globalRequestParameters = new ArrayList<>();
        globalRequestParameters.add(token);


        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .groupName("zz")
                .select()
                // 接口的扫描策略
                .apis(RequestHandlerSelectors.basePackage("com.z.controller")).build()
                .globalRequestParameters(globalRequestParameters);



    }

    ApiInfo apiInfo(){

        Contact zzContact = new Contact(
                "zz",
                "https://gitee.com/zzhaoshuai/big-create",
                "1318781143@qq.com");


       return new ApiInfo(
                "校园实训平台CO后端接口文档",
                "",
                "1.0",
                "urn:tos",
                zzContact,
                "Apache 2.0",
                " ",
                new ArrayList<>());

    }



}
